package org.hjq.controller;

import lombok.extern.slf4j.Slf4j;
import org.hjq.entity.Info;
import org.hjq.entity.User;
import org.hjq.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("{id}")
    public User queryById(@PathVariable("id") Long id,
                          @RequestHeader(value = "Truth", required = false) String truth) {
        System.out.println("truth: " + truth);
        return userService.queryById(id);
    }

    @PostMapping("login")
    public Info login(@RequestParam String username, @RequestParam String password,
                      @RequestParam Integer type) {
        return userService.login(username,password,type);
    }
}
